package com.realgodo.site.web.tag;

import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.web.struts2.Struts2Utils;

import com.realgodo.site.entity.application.communication.Comment;
import com.realgodo.site.entity.space.Space;
import com.realgodo.site.service.communication.CommentManager;
import com.realgodo.site.web.ControllerSupport;
import com.realgodo.util.UserUtil;

/**
 * 评论标签控制器
 * 
 * @author bijiqiang
 * 
 */
public class CommentController extends ControllerSupport {

	private static final long serialVersionUID = -240598454328072514L;

	private Long applicationId;

	private String content;

	@Autowired
	private CommentManager commentManager;

	private Page<Comment> commentPage = new Page<Comment>(10);

	public String execute() {
		commentPage.setPageNo(commentManager.isParamNotNull(getParamMap(),
				Page.PAGE) ? Integer.valueOf((String) commentManager
				.getParamValue(getParamMap(), Page.PAGE)) : 1);// 查询页数
		this.commentPage = commentManager.findComments(commentPage,
				applicationId);
		super.setPageInfo(commentPage);
		Struts2Utils.getRequest().setAttribute("commentPage", commentPage);
		return null;
	}

	public String push() {
		String ok = "2";
		Space current = UserUtil.getCurrentSpace();
		if (applicationId != null && current != null) {
			commentManager.saveComment("", content, applicationId, current);
			ok = "1";
		}
		Struts2Utils.renderJson(ok);
		return null;
	}

	public Long getApplicationId() {
		return applicationId;
	}

	public void setApplicationId(Long applicationId) {
		this.applicationId = applicationId;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

}
